#include "barrier.h"
#include "sched.h"

void do_barrier_init(barrier_t *barrier, int goal)
{
    barrier->goal = goal;
    barrier->current = 0;
    queue_init(&barrier->block_queue);
}

void do_barrier_wait(barrier_t *barrier)
{
    barrier->current++;
    if(barrier->current < barrier->goal){
        do_block(&barrier->block_queue);
    }
    else
    {
        barrier->current = 0;
        do_unblock_all(&barrier->block_queue);
    }
    
}